use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rustcloud_bus::prelude::*;
use serde_json::json;
use tokio::runtime::Runtime;

fn benchmark_message_creation(c: &mut Criterion) {
    c.bench_function("message_creation", |b| {
        b.iter(|| {
            let message = Message::new(
                black_box("test.topic"),
                black_box(json!({"id": 123, "data": "test data"}))
            );
            black_box(message)
        })
    });
}

fn benchmark_publish_subscribe(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();
    
    c.bench_function("publish_subscribe", |b| {
        b.to_async(&rt).iter(|| async {
            let bus = InMemoryMessageBus::new().await.unwrap();
            let subscriber = bus.subscribe("bench.topic").await.unwrap();
            
            let message = Message::new(
                black_box("bench.topic"),
                black_box(json!({"id": 123}))
            );
            
            bus.publish(message).await.unwrap();
            let _received = subscriber.receive_timeout(100).await.unwrap();
        })
    });
}

criterion_group!(benches, benchmark_message_creation, benchmark_publish_subscribe);
criterion_main!(benches);